package com;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.utils.JsonUtil;
import com.utils.RSAUtils;

/**
 * Servlet implementation class JieMiServlet
 */
public class JieMiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取数据
		String uname = request.getParameter("uname");
		String password = request.getParameter("password");
		//String PRIVATEKEY = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIn2zWqU7K/2qm5pOpq5bp9R+3MTnStWTfJU9nC/Vo7UKH9dITPvrELCTK+qlqpx5Fes+l0GY7n6u4n4jyiw4ejsvkZYQ5ww477yLOn2FcoEGuZEwPgSCmfTST0OFUgQqn+/J11k9L92jEHyieE3qmhMkMt0UsVUSJwx/nZxo30ZAgMBAAECgYBD3YHigeuEC4R+14iaf8jo2j0kuGtB3Cxvnlez0otTqw1YyYkBsU49cLKkXvfKVEgM0Ow/QltgKvSBxCE31PrrDka5TygVMqqA/IM7NrDvjUcGLjyoeNmLA8660fWcDxUTlAGN5kxIvUATayVwKVflpWPWu0FPKsWrZustnEo+4QJBAMCmYsWqAKWYMVRXFP3/XGRfio8DV793TOckyBSN9eh8UhgoZyT3u7oeHmDJEwm4aNMHlg1Pcdc6tNsvi1FRCiUCQQC3VNzfF4xOtUgX7vWPL8YVljLuXmy12iVYmg6ofu9l31nwM9FLQ1TRFglvF5LWrIXTQb07PgGd5DJMAQWGsqLlAkAPE7Z9M73TN+L8b8hDzJ1leZi1cpSGdoa9PEKwYR/SrxAZtefEm+LEQSEtf+8OfrEtetWCeyo0pvKKiOEFXytFAkEAgynL/DC0yXsZYUYtmYvshHU5ayFTVagFICbYZeSrEo+BoUDxdI9vl0fU6A5NmBlGhaZ65G+waG5jLc1tTrlvoQJAXBEoPcBNAosiZHQfYBwHqU6mJ9/ZacJh3MtJzGGebfEwJgtln5b154iANqNWXpySBLvkK+Boq7FYRiD83pqmUg==";
		String PRIVATEKEY = "MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBANdCRngdxwBhYGieVrjUO7NCtfdYGnP6qSY99vsJiJi/1m+QAxjC7wZLBs/3zFDxEGffUE9Ra9iXdBVDmlFHGXCXgkpyN/KFc7AwUI1UbJpYrtDlyDHRGATPTP/jPrfnLmr4jR3441VlNJIxlYkbqbTL0atrUxItp7jsLHwTAJ/RAgMBAAECgYEAhcNMcRXn9KeONlS2hTJ1SsbYtrRL8+g+tmHpGURqWqlTQo5WLkvsJpf2ysMsdtvmGvYdPLzW7Ifo/dG9kmZBOp8GiZGTleS3xWU4I1WSjaqEW/r2JNmVd2wshSl5NFFA/8ExQzBPqtaSL4W1yQKwfQOs1QCVagKVWrHG9NJq/bECQQD2OH1Qow8qSaP3oziDodg6MMl4ysVpB3+cXvf7bFKJyzXdzMKf9Sn5+rQcKQiC5d/E3bJrFu0b9TMhkkopP0itAkEA3875YMl5cLcJhLj4OULG0HnNOJao+XWP/o+bFMvdtWjIeucm6wG/8C61i6Z0j+4OuDowphpMAUnWyvZ7s+9kNQJBANzeXaOJMiBoALsy4o5KD3Jbs0807hNCU7nNAzy5tey/qml1tZzRyr7gotKkCGuLk8jAar1fyoEK2rwhw37ust0CQQDZ9WdHqu5pptfOOZUDrtSQEw6ZHaBR0Pv6nUAacK/qC7Gyf4qXM40JC3QiHGlIAj6zi3f1S4bZel+EKacvBORBAkEA1juS56Q+oAIZrBoQPH1gUxOV2g/xHm4Egbvh7Pcz+CxQX3xObecUvO1SQ0Ka2tRz3NegyGN89bFQLNGQOtU0yQ==";
		// 解密
		uname = RSAUtils.decryptDataOnJava(uname, PRIVATEKEY);
		password = RSAUtils.decryptDataOnJava(password, PRIVATEKEY);
		if (password.contains("key")) {
			System.err.println("包含");
		}
		System.err.println(uname);
		System.err.println(password);
		// 用map封装返回的数据
		HashMap<String, Object> result = new HashMap<String, Object>();
		result.put("uname", uname);
		result.put("password", password);

		response.getWriter().print(JsonUtil.toJson(result));

	}

}
